﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ec_System.Models.Web;
using Ilongshi.Oversea.DataAccess;

namespace Ec_System.Service.Web
{
    public class EvaluationService
    {
        /// <summary>
        /// 根据商品的ID获取其的评论
        /// </summary>
        /// <param name="productID"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<EvaluationData> GetEvaluationByProductID(int productID, int pageIndex, int pageSize)
        {
            var cmd = DataCommandManager.GetDataCommand("GetEvaluationByProductID");
            cmd.SetParameterValue("productID", productID);
            cmd.SetParameterValue("pageSize", pageSize);
            cmd.SetParameterValue("pageIndex", pageIndex);

            return cmd.ExecuteEntityList<EvaluationData>();
        }

        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddEvaluation(EvaluationData model)
        {
            var cmd = DataCommandManager.GetDataCommand("AddEvaluation");
            cmd.SetParameterValue("@VendorNumber", model.VendorNumber);
            cmd.SetParameterValue("@productID", model.ProductID);
            cmd.SetParameterValue("@ServiceStar", model.ServiceStar);
            cmd.SetParameterValue("@QualityStar", model.QualityStar);
            cmd.SetParameterValue("@ShipStar", model.ShipStar);
            cmd.SetParameterValue("@Contents", model.Contents);
            cmd.SetParameterValue("@LoginID", model.InUser);
            cmd.SetParameterValue("@OrderId", model.OrderId);
            cmd.SetParameterValue("@OrderDetailId", model.OrderDetailId);

            return cmd.ExecuteNonQuery();

        }

        /// <summary>
        /// 获取评论列表 (带分页)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public EvaluationResponseData GetEvaluationListWithPage(EvaluationRequestData request)
        {
            var cmd = DataCommandManager.GetDataCommand("GetEvaluationListWithPage");
            cmd.SetParameterValue("@PageIndex", request.PageIndex);
            cmd.SetParameterValue("@PageSize", request.PageSize);
            cmd.SetParameterValue("@LoginID", request.LoginID);

            var result = new EvaluationResponseData()
            {
                PageIndex = request.PageIndex,
                PageSize = request.PageSize,              
                Result = cmd.ExecuteEntityList<EvaluationData>(),
                TotalCount = cmd.GetParameterValue<int>("@TotalCount")
            };

            return result;
        }

        /// <summary>
        /// 根据ID获取明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public EvaluationData GetEvaluationDetailByID(int id)
        {
            var cmd = DataCommandManager.GetDataCommand("GetEvaluationDetailByID");
            cmd.SetParameterValue("@ID", id);

            return cmd.ExecuteEntity<EvaluationData>();
        }
    }


}